<template>
	<view>
		<van-tabs active="0" @change="selectTime">
			<van-tab :title="item.label" :name="item.value" v-for="(item,index) in time" :key="index"></van-tab>
		</van-tabs>
		<van-card v-for="(item,index) in scheduleList" :key="index" :price="item.doctorResponse.price"
			
			thumb="https://nwzimg.wezhan.cn/contents/sitefiles2022/10113300/images/3148097.jpg">
			
			<view slot="title" >
				<view style="display: flex; justify-content: space-between;">
					<view  style="font-size: 14px;font-weight:bold">
						
							{{item.doctorResponse.name}} 
					</view> 
					<view >
						号源量:{{item.doctorResponse.remainingQuantity}}
					</view>
				</view>
				
			</view>
			<view slot="desc">
				性别:{{item.doctorResponse.gender}}
				 
				 <van-tag :plain="true" type="danger">{{item.doctorResponse.profession}}</van-tag>
				 <br/>
				 <view class="van-multi-ellipsis--l2" >
				 	个人简介:{{item.doctorResponse.description}}
				 </view>
				 <view >
				 	值班时间:{{scheduleTime[item.scheduleCode]}}
				 </view>
			
				 
			</view>
			<!-- <view slot="tag">
				<van-tag type="primary">{{item.doctorResponse.level}}</van-tag>
			</view> -->
			<view slot="num" style="float: right;">
				<van-button size="mini" @click="handleRegister(item)">挂号</van-button>
			</view>
		</van-card>
		<view v-if="scheduleList.length===0">
			<img style="margin: 10px 5px; padding: 10px;  " src="@/static/custom-empty-image.png" alt="">
		</view>
		<!-- <view style="text-align: center;font-weight: bold;font-size: 20px;">
			暂无排班信息数据
		</view> -->

	</view>
</template>

<script lang="ts" setup>
	import {
		listSchedule
	} from '@/api/schedule';
	import {
		get7Day
	} from '@/utils/date';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		reactive,
		ref
	} from 'vue';
	import {addOrder} from '@/api/orders'  
	const scheduleList = ref({})
	const time = get7Day()
	const scheduleTime = ['全天','上午','下午','晚上']
	const searchInfo = reactive({
		pageNumber: 1,
		pageSize: 100,
		departmentId: '',
		detailTime: time[0].value,
	})
	const dataInfo = ref<any>({})
	const selectTime = (event: any) => {
		searchInfo.detailTime = event.detail.name
		handleScheduleList()
	}
	onLoad((data: any) => {
		searchInfo.departmentId = data.dept2Id
		console.log('');
		handleScheduleList()
		dataInfo.value = data
	})
	const handleScheduleList = async () => {
		scheduleList.value = await listSchedule(searchInfo)
	}	
	const handleRegister = (data:any)=>{
		console.log('data0809',data);
		const requestData = {
			department1Id:dataInfo.value.dept1Id,
			department2Id:dataInfo.value.dept2Id,
			hospitalId:dataInfo.value.hospitalId,
			scheduleId:data.id,
			doctorId:data.doctorId,
			state:0,
			price:data.doctorResponse.price
		}

		
		addOrder(requestData).then((res:any)=>{
			uni.redirectTo({
				url:'/pages/pay/success/success'
			})
		})
		
		
	}
</script>

<style>

</style>
